#pragma once
//@author U094709Y
#include "UserInterface.h"
#include<windows.h>
#pragma comment(lib, "user32")

#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0 )
#define MAX_DISPLAYED_LINES 22
#define ENTER_KEY 13
#define SCROLL_DOWN 40
#define SCROLL_UP 38
#define START_LINE 1
#define INVALID_SELECTION -1
#define NO_TASK_INDEX "-1"
#define TIME_OUT_COUNT 5000

namespace Tasker {

        using namespace System;
        using namespace System::ComponentModel;
        using namespace System::Collections;
        using namespace System::Windows::Forms;
        using namespace System::Data;
        using namespace System::Drawing;

        /// <summary>
        /// Summary for Form1
        /// </summary>
        public ref class Form1 : public System::Windows::Forms::Form
        {
        public:
                Form1(void)
                {
                        InitializeComponent();
                        //
                        //TODO: Add the constructor code here
                        //
						displayBoxPage = 1;
                }

        protected:
                /// <summary>
                /// Clean up any resources being used.
                /// </summary>
                ~Form1()
                {
                        if (components)
                        {
                                delete components;
                        }
                }
        private: System::Windows::Forms::RichTextBox^  displayBox;
        protected:
        private: System::Windows::Forms::TextBox^  commandBox;
        private: System::Windows::Forms::GroupBox^  grpBoxList;
        private: System::Windows::Forms::CheckedListBox^  checkedTaskList;
        private: System::Windows::Forms::DateTimePicker^  dateTimePicker1;
        private: System::Windows::Forms::Timer^  timerOut;
		private: System::Windows::Forms::StatusStrip^  statusStrip;

		private: System::Windows::Forms::ToolStripStatusLabel^  commandStatusLabel;
		private: System::Windows::Forms::TabControl^  tabControl1;
		private: System::Windows::Forms::TabPage^  pendingPage;
		private: System::Windows::Forms::TabPage^  floatPage;
		private: System::Windows::Forms::ListBox^  pendingList;
		private: System::Windows::Forms::ListBox^  floatingList;
		private: System::Windows::Forms::Timer^  timerTimeOut;
		private: System::Windows::Forms::TableLayoutPanel^  tableLayoutPanel1;


		private: System::ComponentModel::IContainer^  components;

        private:
                /// <summary>
                /// Required designer variable.
                /// </summary>
				int displayBoxPage;


#pragma region Windows Form Designer generated code
                /// <summary>
                /// Required method for Designer support - do not modify
                /// the contents of this method with the code editor.
                /// </summary>
                void InitializeComponent(void)
                {
					this->components = (gcnew System::ComponentModel::Container());
					System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
					this->displayBox = (gcnew System::Windows::Forms::RichTextBox());
					this->commandBox = (gcnew System::Windows::Forms::TextBox());
					this->grpBoxList = (gcnew System::Windows::Forms::GroupBox());
					this->checkedTaskList = (gcnew System::Windows::Forms::CheckedListBox());
					this->dateTimePicker1 = (gcnew System::Windows::Forms::DateTimePicker());
					this->timerOut = (gcnew System::Windows::Forms::Timer(this->components));
					this->statusStrip = (gcnew System::Windows::Forms::StatusStrip());
					this->commandStatusLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
					this->tabControl1 = (gcnew System::Windows::Forms::TabControl());
					this->pendingPage = (gcnew System::Windows::Forms::TabPage());
					this->pendingList = (gcnew System::Windows::Forms::ListBox());
					this->floatPage = (gcnew System::Windows::Forms::TabPage());
					this->floatingList = (gcnew System::Windows::Forms::ListBox());
					this->timerTimeOut = (gcnew System::Windows::Forms::Timer(this->components));
					this->tableLayoutPanel1 = (gcnew System::Windows::Forms::TableLayoutPanel());
					this->grpBoxList->SuspendLayout();
					this->statusStrip->SuspendLayout();
					this->tabControl1->SuspendLayout();
					this->pendingPage->SuspendLayout();
					this->floatPage->SuspendLayout();
					this->tableLayoutPanel1->SuspendLayout();
					this->SuspendLayout();
					// 
					// displayBox
					// 
					this->displayBox->BackColor = System::Drawing::Color::WhiteSmoke;
					this->displayBox->BorderStyle = System::Windows::Forms::BorderStyle::None;
					this->displayBox->Cursor = System::Windows::Forms::Cursors::IBeam;
					this->displayBox->Dock = System::Windows::Forms::DockStyle::Fill;
					this->displayBox->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
						static_cast<System::Byte>(0)));
					this->displayBox->ImeMode = System::Windows::Forms::ImeMode::Off;
					this->displayBox->Location = System::Drawing::Point(39, 158);
					this->displayBox->Name = L"displayBox";
					this->displayBox->ReadOnly = true;
					this->tableLayoutPanel1->SetRowSpan(this->displayBox, 3);
					this->displayBox->ScrollBars = System::Windows::Forms::RichTextBoxScrollBars::Vertical;
					this->displayBox->Size = System::Drawing::Size(280, 327);
					this->displayBox->TabIndex = 7;
					this->displayBox->TabStop = false;
					this->displayBox->Text = L"";
					// 
					// commandBox
					// 
					this->commandBox->AutoCompleteCustomSource->AddRange(gcnew cli::array< System::String^  >(1) {L"add [name]  -date   [DD/MM/YYYY]"});
					this->commandBox->BackColor = System::Drawing::Color::PaleTurquoise;
					this->commandBox->BorderStyle = System::Windows::Forms::BorderStyle::None;
					this->tableLayoutPanel1->SetColumnSpan(this->commandBox, 3);
					this->commandBox->Dock = System::Windows::Forms::DockStyle::Fill;
					this->commandBox->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
						static_cast<System::Byte>(0)));
					this->commandBox->Location = System::Drawing::Point(39, 516);
					this->commandBox->Multiline = true;
					this->commandBox->Name = L"commandBox";
					this->commandBox->ScrollBars = System::Windows::Forms::ScrollBars::Vertical;
					this->commandBox->Size = System::Drawing::Size(514, 60);
					this->commandBox->TabIndex = 1;
					this->commandBox->KeyDown += gcnew System::Windows::Forms::KeyEventHandler(this, &Form1::commandBox_KeyDown);
					this->commandBox->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &Form1::commandBox_KeyPress);
					this->commandBox->Leave += gcnew System::EventHandler(this, &Form1::commandBox_Leave);
					// 
					// grpBoxList
					// 
					this->grpBoxList->Anchor = static_cast<System::Windows::Forms::AnchorStyles>((((System::Windows::Forms::AnchorStyles::Top | System::Windows::Forms::AnchorStyles::Bottom) 
						| System::Windows::Forms::AnchorStyles::Left) 
						| System::Windows::Forms::AnchorStyles::Right));
					this->grpBoxList->BackColor = System::Drawing::Color::Transparent;
					this->grpBoxList->Controls->Add(this->checkedTaskList);
					this->grpBoxList->Controls->Add(this->dateTimePicker1);
					this->grpBoxList->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
						static_cast<System::Byte>(0)));
					this->grpBoxList->ForeColor = System::Drawing::Color::SaddleBrown;
					this->grpBoxList->Location = System::Drawing::Point(357, 138);
					this->grpBoxList->Name = L"grpBoxList";
					this->tableLayoutPanel1->SetRowSpan(this->grpBoxList, 2);
					this->grpBoxList->Size = System::Drawing::Size(196, 154);
					this->grpBoxList->TabIndex = 8;
					this->grpBoxList->TabStop = false;
					this->grpBoxList->Text = L"Tasks for";
					// 
					// checkedTaskList
					// 
					this->checkedTaskList->BackColor = System::Drawing::Color::WhiteSmoke;
					this->checkedTaskList->BorderStyle = System::Windows::Forms::BorderStyle::None;
					this->checkedTaskList->Dock = System::Windows::Forms::DockStyle::Fill;
					this->checkedTaskList->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
						static_cast<System::Byte>(0)));
					this->checkedTaskList->FormattingEnabled = true;
					this->checkedTaskList->Location = System::Drawing::Point(3, 36);
					this->checkedTaskList->Name = L"checkedTaskList";
					this->checkedTaskList->Size = System::Drawing::Size(190, 115);
					this->checkedTaskList->TabIndex = 2;
					this->checkedTaskList->ItemCheck += gcnew System::Windows::Forms::ItemCheckEventHandler(this, &Form1::checkedTaskList_ItemCheck);
					this->checkedTaskList->SelectedValueChanged += gcnew System::EventHandler(this, &Form1::checkedTaskList_SelectedValueChanged);
					this->checkedTaskList->Leave += gcnew System::EventHandler(this, &Form1::checkedTaskList_Leave);
					// 
					// dateTimePicker1
					// 
					this->dateTimePicker1->Checked = false;
					this->dateTimePicker1->Dock = System::Windows::Forms::DockStyle::Top;
					this->dateTimePicker1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
						static_cast<System::Byte>(0)));
					this->dateTimePicker1->Location = System::Drawing::Point(3, 16);
					this->dateTimePicker1->Name = L"dateTimePicker1";
					this->dateTimePicker1->Size = System::Drawing::Size(190, 20);
					this->dateTimePicker1->TabIndex = 1;
					this->dateTimePicker1->ValueChanged += gcnew System::EventHandler(this, &Form1::dateTimePicker1_ValueChanged);
					// 
					// timerOut
					// 
					this->timerOut->Interval = 500;
					this->timerOut->Tick += gcnew System::EventHandler(this, &Form1::timerOut_Tick);
					// 
					// statusStrip
					// 
					this->statusStrip->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) {this->commandStatusLabel});
					this->statusStrip->Location = System::Drawing::Point(0, 557);
					this->statusStrip->Name = L"statusStrip";
					this->statusStrip->Size = System::Drawing::Size(583, 22);
					this->statusStrip->TabIndex = 9;
					this->statusStrip->Text = L"statusStrip1";
					// 
					// commandStatusLabel
					// 
					this->commandStatusLabel->Name = L"commandStatusLabel";
					this->commandStatusLabel->Size = System::Drawing::Size(122, 17);
					this->commandStatusLabel->Text = L"commandStatusLabel";
					// 
					// tabControl1
					// 
					this->tabControl1->Controls->Add(this->pendingPage);
					this->tabControl1->Controls->Add(this->floatPage);
					this->tabControl1->Dock = System::Windows::Forms::DockStyle::Fill;
					this->tabControl1->HotTrack = true;
					this->tabControl1->ItemSize = System::Drawing::Size(95, 18);
					this->tabControl1->Location = System::Drawing::Point(357, 318);
					this->tabControl1->Name = L"tabControl1";
					this->tabControl1->Padding = System::Drawing::Point(0, 0);
					this->tabControl1->SelectedIndex = 0;
					this->tabControl1->Size = System::Drawing::Size(196, 167);
					this->tabControl1->SizeMode = System::Windows::Forms::TabSizeMode::Fixed;
					this->tabControl1->TabIndex = 10;
					// 
					// pendingPage
					// 
					this->pendingPage->Controls->Add(this->pendingList);
					this->pendingPage->Location = System::Drawing::Point(4, 22);
					this->pendingPage->Name = L"pendingPage";
					this->pendingPage->Size = System::Drawing::Size(188, 141);
					this->pendingPage->TabIndex = 0;
					this->pendingPage->Text = L"Pending Tasks";
					this->pendingPage->UseVisualStyleBackColor = true;
					// 
					// pendingList
					// 
					this->pendingList->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(246)), static_cast<System::Int32>(static_cast<System::Byte>(212)), 
						static_cast<System::Int32>(static_cast<System::Byte>(138)));
					this->pendingList->BorderStyle = System::Windows::Forms::BorderStyle::None;
					this->pendingList->Dock = System::Windows::Forms::DockStyle::Fill;
					this->pendingList->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
						static_cast<System::Byte>(0)));
					this->pendingList->FormattingEnabled = true;
					this->pendingList->ItemHeight = 15;
					this->pendingList->Location = System::Drawing::Point(0, 0);
					this->pendingList->Name = L"pendingList";
					this->pendingList->Size = System::Drawing::Size(188, 141);
					this->pendingList->TabIndex = 0;
					this->pendingList->SelectedValueChanged += gcnew System::EventHandler(this, &Form1::selectedValueChanged);
					this->pendingList->Leave += gcnew System::EventHandler(this, &Form1::selectList_Leave);
					// 
					// floatPage
					// 
					this->floatPage->Controls->Add(this->floatingList);
					this->floatPage->Location = System::Drawing::Point(4, 22);
					this->floatPage->Name = L"floatPage";
					this->floatPage->Size = System::Drawing::Size(188, 141);
					this->floatPage->TabIndex = 1;
					this->floatPage->Text = L"Floating Tasks";
					this->floatPage->UseVisualStyleBackColor = true;
					// 
					// floatingList
					// 
					this->floatingList->BackColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(246)), static_cast<System::Int32>(static_cast<System::Byte>(212)), 
						static_cast<System::Int32>(static_cast<System::Byte>(138)));
					this->floatingList->BorderStyle = System::Windows::Forms::BorderStyle::None;
					this->floatingList->Dock = System::Windows::Forms::DockStyle::Fill;
					this->floatingList->FormattingEnabled = true;
					this->floatingList->Location = System::Drawing::Point(0, 0);
					this->floatingList->Name = L"floatingList";
					this->floatingList->Size = System::Drawing::Size(188, 141);
					this->floatingList->TabIndex = 0;
					this->floatingList->SelectedValueChanged += gcnew System::EventHandler(this, &Form1::selectedValueChanged);
					this->floatingList->Leave += gcnew System::EventHandler(this, &Form1::selectList_Leave);
					// 
					// timerTimeOut
					// 
					this->timerTimeOut->Interval = 5000;
					this->timerTimeOut->Tick += gcnew System::EventHandler(this, &Form1::timerTimeOut_Tick);
					// 
					// tableLayoutPanel1
					// 
					this->tableLayoutPanel1->BackColor = System::Drawing::Color::Transparent;
					this->tableLayoutPanel1->ColumnCount = 5;
					this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
						6.185567F)));
					this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
						49.1409F)));
					this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
						5.498282F)));
					this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
						34.7079F)));
					this->tableLayoutPanel1->ColumnStyles->Add((gcnew System::Windows::Forms::ColumnStyle(System::Windows::Forms::SizeType::Percent, 
						4.467354F)));
					this->tableLayoutPanel1->Controls->Add(this->tabControl1, 3, 4);
					this->tableLayoutPanel1->Controls->Add(this->displayBox, 1, 2);
					this->tableLayoutPanel1->Controls->Add(this->grpBoxList, 3, 1);
					this->tableLayoutPanel1->Controls->Add(this->commandBox, 1, 6);
					this->tableLayoutPanel1->Dock = System::Windows::Forms::DockStyle::Fill;
					this->tableLayoutPanel1->Location = System::Drawing::Point(0, 0);
					this->tableLayoutPanel1->Name = L"tableLayoutPanel1";
					this->tableLayoutPanel1->RowCount = 7;
					this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 23.31606F)));
					this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 3.454232F)));
					this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 24.17962F)));
					this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 3.454232F)));
					this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 29.8791F)));
					this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 4.317789F)));
					this->tableLayoutPanel1->RowStyles->Add((gcnew System::Windows::Forms::RowStyle(System::Windows::Forms::SizeType::Percent, 11.05354F)));
					this->tableLayoutPanel1->Size = System::Drawing::Size(583, 579);
					this->tableLayoutPanel1->TabIndex = 11;
					// 
					// Form1
					// 
					this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
					this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
					this->BackColor = System::Drawing::SystemColors::Control;
					this->BackgroundImage = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"$this.BackgroundImage")));
					this->BackgroundImageLayout = System::Windows::Forms::ImageLayout::Stretch;
					this->ClientSize = System::Drawing::Size(583, 579);
					this->Controls->Add(this->statusStrip);
					this->Controls->Add(this->tableLayoutPanel1);
					this->Icon = (cli::safe_cast<System::Drawing::Icon^  >(resources->GetObject(L"$this.Icon")));
					this->Name = L"Form1";
					this->Text = L"Tasker";
					this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
					this->grpBoxList->ResumeLayout(false);
					this->statusStrip->ResumeLayout(false);
					this->statusStrip->PerformLayout();
					this->tabControl1->ResumeLayout(false);
					this->pendingPage->ResumeLayout(false);
					this->floatPage->ResumeLayout(false);
					this->tableLayoutPanel1->ResumeLayout(false);
					this->tableLayoutPanel1->PerformLayout();
					this->ResumeLayout(false);
					this->PerformLayout();

				}
#pragma endregion
				//@author U094709Y
        private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                                 // Testing generateMessage
                                 //String^ str2 = gcnew String(UserInterface::MESSAGE[UserInterface::MESSAGE_TYPE::ADDED].c_str());
                                 //displayBox->AppendText(str2);

                                 //Demonstrate usage of generateMessage
                                 /*UserInterface UI;
                                 String^ str2 = gcnew String(UI.generateMessage(UserInterface::MESSAGE_TYPE::ADDED, "asdfjk").c_str());
                                 displayBox->AppendText(str2);*/
                                 UserInterface UI;
                                 UI.startingExecutor();
								 loadCheckedBoxTaskList(UI.getDateOrTime(dateTimePicker1->Value.ToString()));
								 

								 loadPendingList();
								 loadFloatingList();

                                 printMessage(UI.generateWelcomeMessage());

								 //Testing toolstripstatus label
								 printSystemMessage();
								 
                         }

#pragma region Loading Task Lists

			void loadCheckedBoxTaskList(string date)
			{
				UserInterface UI;
				try
				{
					DataTable^ taskList = UI.getTaskList(date);
					checkedTaskList->DataSource = taskList;			//cause of System.NullReferenceException thrown
					checkedTaskList->DisplayMember = "subject";
					checkedTaskList->ValueMember = "index";
					int taskSize = taskList->Rows->Count;
					for(int i = 0; i < taskSize; i++)
					{
						checkedTaskList->SetItemChecked(i, (bool)taskList->Rows[i]->default["done"]);
					}
				}
				catch (string e)
				{
					checkedTaskList->DisplayMember = "";
					checkedTaskList->ValueMember = "";
					checkedTaskList->DataSource = NULL;
					date = "No task for " + date;
					checkedTaskList->Items->Add(gcnew String(date.c_str()), CheckState::Indeterminate);	

				}
				checkedTaskList->ClearSelected();
			}

			void loadPendingList(void)
			{
				UserInterface UI;
				try
				{
					DataTable^ taskList = UI.getPendingList();
					pendingList->DataSource = taskList;
					pendingList->DisplayMember = "subject";
					pendingList->ValueMember = "index";
					pendingList->SetSelected(0, false);
				}
				catch (string e)
				{
					pendingList->DisplayMember = "";
					pendingList->ValueMember = "";
					pendingList->DataSource = NULL;
				}
			}

			void loadFloatingList(void)
			{
				UserInterface UI;
				try
				{
					DataTable^ taskList = UI.getFloatingList();
					floatingList->DataSource = taskList;
					floatingList->DisplayMember = "subject";
					floatingList->ValueMember = "index";
					floatingList->SetSelected(0, false);
				}
				catch (string e)
				{
					floatingList->DisplayMember = "";
					floatingList->ValueMember = "";
					floatingList->DataSource = NULL;
				}
			}


#pragma endregion

#pragma region commandBox

private: System::Void commandBox_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
                        if(KEY_DOWN(ENTER_KEY) && (commandBox->Text != ""))
                        {
                            UserInterface UI;
                            string commandString = UI.readUserInput(commandBox->Text);
                            string results = UI.sendingInputToExecutor(commandString);

                            printMessage(results);
                            commandBox->Clear();

							//Check if system is to be closed
                            if(displayBox->Text == "Exiting...")
								timerOut->Enabled = true;

							//update other components
							printSystemMessage();
							System::EventArgs^ e = gcnew EventArgs();
							dateTimePicker1_ValueChanged(dateTimePicker1, e);
							loadFloatingList();
							loadPendingList();
                        }
                }


private: System::Void commandBox_KeyDown(System::Object^  sender, System::Windows::Forms::KeyEventArgs^  e) {
			 if (displayBoxPage < START_LINE)
				 displayBoxPage = START_LINE;
			 int scrollPoint;
			 int textBoxLength = commandBox->Text->Length;
			 bool isCmdBoxEmpty = ((textBoxLength >= 0) && (textBoxLength < 3));
			 if(isCmdBoxEmpty)
			 {
				 if((e->KeyValue == SCROLL_DOWN))
					{
						scrollPoint = displayBox->GetFirstCharIndexFromLine(displayBoxPage * MAX_DISPLAYED_LINES);
						if (scrollPoint != INVALID_SELECTION)
						{
							displayBoxPage++;
							displayBox->SelectionStart = scrollPoint;
							displayBox->ScrollToCaret();
						}
					} else if((e->KeyValue == SCROLL_UP))
					 {
						 displayBoxPage = (displayBoxPage > START_LINE)? displayBoxPage-1: START_LINE-1;
						 scrollPoint = displayBox->GetFirstCharIndexFromLine(displayBoxPage * MAX_DISPLAYED_LINES);
						 if(scrollPoint != INVALID_SELECTION)
						 {
							 displayBox->SelectionStart = scrollPoint;
							 displayBox->ScrollToCaret();
						 }
					 }
			 }
		 }
				 
private: System::Void commandBox_Leave(System::Object^  sender, System::EventArgs^  e) {
			 timerTimeOut->Enabled = true;
		 }

#pragma endregion

#pragma region timers
		 		 
private: System::Void timerTimeOut_Tick(System::Object^  sender, System::EventArgs^  e) {
				 commandBox->Focus();
				 timerTimeOut->Enabled = false;
			 }

			void resetTimeOutCount(void)
			{
				timerTimeOut->Interval = TIME_OUT_COUNT;
			}

private: System::Void timerOut_Tick(System::Object^  sender, System::EventArgs^  e) {
					this->Close();
			}

#pragma endregion

#pragma region Message Display

		 void printMessage(string msg) {
				if(!msg.empty())
				{
					displayBox->Clear();
					String^ display = gcnew String(msg.c_str());
					displayBox->AppendText(display);
				}
            }

			void printSystemMessage() {
				//For Testing
				//string msg = "Loading Form";

				UserInterface UI;
				string msg = UI.getSystemMessage();

				statusStrip->Items->default["commandStatusLabel"]->Text = gcnew String(msg.c_str());
			}

#pragma endregion

#pragma region GroupBox Tasks for

private: System::Void dateTimePicker1_ValueChanged(System::Object^  sender, System::EventArgs^  e) {
			UserInterface UI;
			String^ selectedDateTime = dateTimePicker1->Value.ToString();
			loadCheckedBoxTaskList(UI.getDateOrTime(selectedDateTime));
		}

private: System::Void checkedTaskList_ItemCheck(System::Object^  sender, System::Windows::Forms::ItemCheckEventArgs^  e) {
			 UserInterface UI;
			 if(e->NewValue != e->CurrentValue)
			 {
				 DataRowView^ listItem = (DataRowView^)checkedTaskList->Items->default[e->Index];	//get the checkedItem from checkedTaskList
				 String^ fileIndex = listItem[checkedTaskList->ValueMember]->ToString();
				 bool isTaskDone = (e->NewValue == CheckState::Checked)? true: false;
				 string commandString = UI.readUserInput(fileIndex, UI.DISPLAY_TYPE::CHECKEDBOXLIST, isTaskDone);
				 UI.sendingInputToExecutor(commandString);

				 //update other components
				 printSystemMessage();
				 loadPendingList();
			 }
		 }

		 private: System::Void checkedTaskList_SelectedValueChanged(System::Object^  sender, System::EventArgs^  e) {
				 UserInterface UI;
				 if(checkedTaskList->ContainsFocus && checkedTaskList->SelectedIndex != INVALID_SELECTION)
				 {
					String^ taskIndex = checkedTaskList->SelectedValue->ToString();
					string commandString = UI.readUserInput(taskIndex, UI.DISPLAY_TYPE::SELECTLIST_PENDING);
					string results = UI.sendingInputToExecutor(commandString);

					//update other components
					if (taskIndex == NO_TASK_INDEX)
						printSystemMessage();
					printMessage(results);
					resetTimeOutCount();
				 }
		 }

private: System::Void checkedTaskList_Leave(System::Object^  sender, System::EventArgs^  e) {
			 checkedTaskList->ClearSelected();
		 }
#pragma endregion

#pragma region Pending and Floating Task Lists

private: System::Void selectedValueChanged(System::Object^ sender, System::EventArgs^  e) {
			 UserInterface UI;
			 ListBox^ taskList = (ListBox^) sender;
			 if(taskList->ContainsFocus && taskList->SelectedIndex != INVALID_SELECTION)
			 {
				String^ taskIndex = taskList->SelectedValue->ToString();
				string commandString = UI.readUserInput(taskIndex, UI.DISPLAY_TYPE::SELECTLIST_PENDING);
				string results = UI.sendingInputToExecutor(commandString);

				//update other components
				printSystemMessage();
				printMessage(results);
				resetTimeOutCount();
			 }
			 
		 }

private: System::Void selectList_Leave(System::Object^  sender, System::EventArgs^  e) {
			 ListBox^ taskList = (ListBox^) sender;
			 taskList->SetSelected(0, false);
		 }

#pragma endregion


};
}